package com.vancouver.knows.business.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pangu.util.StringUtil;
import com.vancouver.knows.business.bean.CommentInfo;

/**
 * 查询评论列表解析
 * <p/>
 * Created by cxlin
 */
public class FetchCommentsHandler extends ACheckableJsonParser {

	private List<CommentInfo> commentInfoList;

	@Override
	protected void parserContent(JSONObject content) throws Exception {
		String posts = content.getString("comment_details");
		if (StringUtil.isEmptyString(posts)) {
			commentInfoList = new ArrayList<CommentInfo>();
			return;
		}

		commentInfoList = JSON.parseArray(posts, CommentInfo.class);
		commentInfoList = removeDetailCommentsInfo(commentInfoList);

	}

	public List<CommentInfo> getCommentInfoList() {
		return commentInfoList;
	}

	private List<CommentInfo> removeDetailCommentsInfo(List<CommentInfo> commentList) {
		for (int i = 0; i < commentList.size(); i++) {
			if ("trash".equals(commentList.get(i).getApproved())) {
				commentList.remove(i);
				i--;
			}
		}
		return commentList;
	}

}
